﻿
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;




[RequireComponent(typeof(CameraFilterPack_Color_RGB))]

[RequireComponent(typeof(CameraFilterPack_AAA_Blood_Plus))]

[RequireComponent(typeof(CameraFilterPack_AAA_BloodOnScreen))]
public class MyCameraEffect : MonoBehaviour
{
    private CameraFilterPack_Color_RGB turnBlackEffect;
    CameraFilterPack_AAA_Blood_Plus splashBloodEffect;
    CameraFilterPack_AAA_BloodOnScreen fallDownBloodEffect;
    public bool isTurnToBlack;
    public bool isStartBlood;

    public static MyCameraEffect instance;
    public event Action OnCancleBlack;
    void Awake()
    {
        instance = this;
        turnBlackEffect = GetComponent<CameraFilterPack_Color_RGB>();
        splashBloodEffect= GetComponent<CameraFilterPack_AAA_Blood_Plus>();
        fallDownBloodEffect = GetComponent<CameraFilterPack_AAA_BloodOnScreen>();
        splashBloodEffect.enabled = false;
        splashBloodEffect.Blood_8 = 1;
        splashBloodEffect.Blood_9 = 1;
        fallDownBloodEffect.enabled = false;
        turnBlackEffect.enabled = true;
        fallDownBloodEffect.Blood_On_Screen = 0.02f;
        fallDownBloodEffect.Blood_Distortion_Speed = 0.1f;
        //TurnToBlack();

        //SplashBlood();

        //FallDownBlood();
    }

    void Update()
    {
        if (isTurnToBlack)
        {
            turnBlackEffect.enabled = true;
            turnBlackEffect.ColorRGB = Color.Lerp(turnBlackEffect.ColorRGB, Color.black, Time.time * 0.001f);
        }
        else
        {
            turnBlackEffect.enabled = false;
        }
        if (isStartBlood)
        {
            fallDownBloodEffect.Blood_On_Screen = Mathf.Lerp(fallDownBloodEffect.Blood_On_Screen,1.2f,Time.time*0.0025f);
        }

       
    }

    /// <summary>
    /// 整个死亡过程连贯特效
    /// </summary>
    public void PlayDeadBlood()
    {
        SplashBlood();     
        Invoke("CancelBlood", 5f);
        Invoke("CancleBlack",8f);
        
    }

    /// <summary>
    /// 停止流血特效
    /// </summary>
    public void CancelBlood()
    {
        Debug.Log("CancelBlood");
        splashBloodEffect.enabled = false;
        fallDownBloodEffect.enabled = false;
        TurnToBlack();
    }
    public void CancleBlack()
    {
        Debug.Log("CancleBlack");
        isTurnToBlack = false;
        OnCancleBlack();
    }
    /// <summary>
    /// 摄像机变黑
    /// </summary>
    public void TurnToBlack()
    {
        isTurnToBlack = true;
    }



    /// <summary>
    /// 飞溅血
    /// </summary>
    public void SplashBlood()
    {
        splashBloodEffect.enabled = true;
    }





}
